home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / BMP2BGI1.ZIP / BMP2BGI3.C < prev    next >
C/C++ Source or Header  |  1991-05-25  |  3KB  |  58 lines

  1. //////////////////////////////////////////////////////////////////////////
  2. // StoreBGI: Now that image is showing, let's store it to file.  If image
  3. //           is larger than 64K, then it is broken up into 5 chunks
  4. //////////////////////////////////////////////////////////////////////////
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <alloc.h>
  9. #include <graphics.h>
  10. #include "bgi.h"
  11.  
  12. void StoreBGI (FILE *F, int Width, int Height, char far *VidBuf[5])
  13. {
  14.         int i, yend, yincr, ystart=0;           // bookkeeping vars
  15.         unsigned size;
  16.  
  17.  
  18.         size = imagesize(0, 0, Width, Height);  // How big are we talking?
  19.  
  20.                                                 // If image is less than 64K,
  21.                                                 // prev. function changes 'size'
  22.                                                 // to 0 if image > 64K-1
  23.         if (size != NULLIMAGESIZE)
  24.         {                                       // Alloc space for image
  25.                 VidBuf[0] = (char far *) farmalloc((unsigned long) Width * Height);
  26.                                                 // read image from screen             
  27.                 getimage(0, 0, Width, Height, VidBuf[0]);
  28.                                                 // then write it out to file
  29.                 fwrite(VidBuf[0], sizeof(char), size, F); 
  30.                 farfree(VidBuf[0]);             // And free up memory
  31.         }
  32.         else                                    // image is 64k+, so chunk 
  33.         {                                       // it into fifths
  34.              yincr = (Height+1) / 5;
  35.              yend = yincr;
  36.              size = imagesize(0, ystart, Width, yend);
  37.  
  38.              for (i=0; i < 5; i++)
  39.              {                                  // Alloc memory
  40.              if ((VidBuf[i] = (char far *) farmalloc((unsigned)size)) == NULL)
  41.              {
  42.                         closegraph();           // Oops, not enough memory
  43.                         printf("StoreBGI> out of memory.  %lu bytes requested\n\n", size);
  44.                         exit(1);
  45.              }
  46.                                                 // read in chunk from screen
  47.                 getimage(0, ystart, Width, yend, VidBuf[i]);
  48.                                                 // and write chunk to file 
  49.                 fwrite(VidBuf[i], sizeof(char), size, F);
  50.                 farfree(VidBuf[i]);             // then freeing up memory
  51.                 ystart = yend + 1;              // advance boundaries of 
  52.                 yend += yincr + 1;              // next chunk
  53.              }
  54.  
  55.  
  56.         }
  57. }                
  58.